Fix: crystal i REPL fails with pcre2_compile_8 on Windows MinGW#16795
Open
calospoimen wants to merge 1 commit intocrystal-lang:masterfrom
Open
Fix: crystal i REPL fails with pcre2_compile_8 on Windows MinGW#16795calospoimen wants to merge 1 commit intocrystal-lang:masterfrom
calospoimen wants to merge 1 commit intocrystal-lang:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using
crystal i(interpreter/REPL) on Windows MinGW UCRT64, any use of regular expressions raises:The same code works correctly with
crystal runorcrystal build.Fixes #16794
Root Cause
Two bugs were found:
1.
interpreter/[context.cr](http://context.cr/)— lazy loader initializationThe loader is initialized once (lazy getter) using
program.lib_flagsat the firstc_functioncall. In REPL mode, pcre2 is not inlib_flagsat loader init time because Regex is defined in prelude but not yet used. When the user types the first regex, pcre2 is added tolib_flagsbut the loader is already cached. File mode works because prelude and file are analyzed together.2.
loader/[mingw.cr](http://mingw.cr/)—LoadLibraryExWhandle issueLoadLibraryExWwith a bare DLL name returns a handle for already-loaded process DLLs whereGetProcAddresssubsequently fails. UsingGetModuleHandleExWfirst returns the canonical handle that works correctly.Fix
src/compiler/crystal/loader/[mingw.cr](http://mingw.cr/):load_dll?now usesGetModuleHandleExWfirst, falls back to full-pathLoadLibraryExW; addedresolve_dll_full_pathto find the DLL in search paths and siblingbin/directories.src/compiler/crystal/interpreter/[context.cr](http://context.cr/): addeddll_search_pathsfor Windows MinGW, trackslib_flagsat loader init time, addedupdate_loaderto dynamically load new-llibraries whenlib_flagschanges.Test Case